Python Concurrency with asyncio by Matthew Fowler

Python Concurrency with asyncio by Matthew Fowler

Author:Matthew Fowler [Fowler, Matthew]
Language: eng
Format: epub, pdf
Publisher: Manning Publications Co.
Published: 2022-02-12T23:00:00+00:00


7.4 Event loops in separate threads

We have mainly focused on building applications that are completely implemented from the bottom up with coroutines and asyncio. When we’ve had any work that does not fit within a single-threaded concurrency model, we have run it inside of threads or processes. Not all applications will fit into this paradigm. What if we’re working in an existing synchronous application and we want to incorporate asyncio?

One such situation where we can run into this scenario is building desktop user interfaces. The frameworks to build GUIs usually run their own event loop, and the event loop blocks the main thread. This means that any long-running operations can cause the user interface to freeze. In addition, this UI event loop will block us from creating an asyncio event loop. In this section, we’ll learn how to use multithreading to run multiple event loops at the same time by building a responsive HTTP stress-testing user interface in Tkinter.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.